#ifndef __WX_VECTOR_PLOT_CURVE_H__
#define __WX_VECTOR_PLOT_CURVE_H__

////////////////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////////////////

#include <vector>
#include "wx/plot/plot.h"

////////////////////////////////////////////////////////////////////////////////
// Namespaces
////////////////////////////////////////////////////////////////////////////////

namespace wxToolkit {

////////////////////////////////////////////////////////////////////////////////
// Implementation
////////////////////////////////////////////////////////////////////////////////

/**
 *  This class defines a vector x-indexed curve for the wxPlotCurve interface
 */

class wxVectorIndexedPlotCurve : public wxPlotCurve {

	public:

		/// Constructor
		wxVectorIndexedPlotCurve( int offsetY, double startY, double endY, unsigned int buf_size = 1000 )
		: wxPlotCurve( offsetY, startY, endY ) , buf_size(buf_size) {}

		/// First X value
		virtual wxInt32 GetStartX() { return 0; }

		/// Last X value
		virtual wxInt32 GetEndX() { return this->points.size()-1; }

		/// Get the curve's Y value at the X coordinate
		virtual double GetY(wxInt32 x) {
            if ((x < 0) || (x >= (wxInt32)this->points.size())) return 0.;
            return this->points[x];
        }

		/// Add a point access
		void AddPoint(const double value) {
			while (this->points.size() >= this->buf_size)
				this->points.erase(this->points.begin());
			this->points.push_back(value);
		}

		/// Add points
		void AddPoints(const std::vector<double> values) {
			for (unsigned int i=0; i<values.size(); ++i) {
				while (this->points.size() >= this->buf_size)
					this->points.erase(this->points.begin());
				this->points.push_back(values[i]);
			}
		}

		/// Points access (read only)
		const std::vector<double> & GetPoints() const { return this->points; }

		/// Set the buffer size
		void SetBufferSize(const unsigned int s) {
			this->buf_size = s;
			while (this->points.size() >= this->buf_size)
				this->points.erase(this->points.begin());
		}

		/// Clear the data
		void Clear() { this->points.clear(); }

	protected:

		/// X-Indexed Points
		std::vector<double> points;

		/// Buffer size
		unsigned int buf_size;

};

////////////////////////////////////////////////////////////////////////////////
// Closing Namespaces
////////////////////////////////////////////////////////////////////////////////

}

////////////////////////////////////////////////////////////////////////////////

#endif
